
//
//  AddressDetailTableViewCell.m
//  HuaRun2
//
//  Created by admin on 17/8/29.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "AddressDetailTableViewCell.h"
#import "AddressModel.h"

@interface AddressDetailTableViewCell ()
@property (nonatomic, strong) UIView * backView;

//名字
@property (nonatomic, strong) UILabel * nameLab;
//创建人
@property (nonatomic, strong) UILabel * createLab;
//最后修改人
@property (nonatomic, strong) UILabel * finalCreateLab;

@end

@implementation AddressDetailTableViewCell

#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.contentView.backgroundColor = RGBA(249, 249, 249, 1);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    
    [self.contentView addSubview:self.backView];
    [self.contentView addSubview:self.nameLab];
    
    [self.contentView addSubview:self.createLab];
    [self.contentView addSubview:self.finalCreateLab];
    
}

- (void)layoutInit {
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView);
    }];
    
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.top.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
    }];
    
    [self.createLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.nameLab);
        make.top.mas_equalTo(ws.nameLab.mas_bottom).offset(kMargin10);
        make.right.mas_equalTo(ws.backView).offset(-kMargin10);
    }];
    
    [self.finalCreateLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(ws.createLab);
        make.top.mas_equalTo(ws.createLab.mas_bottom).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView.mas_bottom).offset(-kMargin10);
    }];

}

#pragma mark setter getter

#pragma mark 测试  字段没有取全
- (void)setAddressModel:(AddressModel *)addressModel {
    _addressModel = addressModel;
    _nameLab.text = [NSString stringWithFormat:@"%@", addressModel.name? addressModel.name : @""];
    
    //    name address1English
    //    address2English  cityTownEnglish
    //    address1Chinese address2Chinese
    //    cityTownChinese zipPostalEnglish
    
    NSString * text = [NSString stringWithFormat:@"%@ \n%@ \n%@ \n%@ \n%@ \n%@ \n%@\n",
                      addressModel.address1English ? addressModel.address1English : @"",
                      addressModel.address2English ? addressModel.address2English : @"",
                      addressModel.cityTownEnglish ? addressModel.cityTownEnglish : @"",
                      addressModel.address1Chinese ? addressModel.address1Chinese : @"",
                      addressModel.address2Chinese ? addressModel.address2Chinese : @"",
                      addressModel.cityTownChinese ? addressModel.cityTownChinese : @"",
                      addressModel.zipPostalChinese ? addressModel.zipPostalChinese : @""];
    [_createLab resetLineSpaceHeight5WithStr:text];
}

- (UILabel *)nameLab {
    if (!_nameLab) {
        self.nameLab = [UILabel new];
        _nameLab.textAlignment = NSTextAlignmentLeft;
        _nameLab.font = kGeneralFontSize;
        _nameLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _nameLab;
}

- (UIView *)backView {
    if (!_backView) {
        self.backView = [UIView new];
        _backView.backgroundColor = [UIColor whiteColor];
    }
    return _backView;
}

- (UILabel *)createLab {
    if (!_createLab) {
        self.createLab = [UILabel new];
        _createLab.textAlignment = NSTextAlignmentLeft;
        _createLab.font = kGeneralFontSize;
        _createLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _createLab.text =      @"地址创建人    ";
        _createLab.numberOfLines = 0;
    }
    return _createLab;
}

- (UILabel *)finalCreateLab {
    if (!_finalCreateLab) {
        self.finalCreateLab = [UILabel new];
        _finalCreateLab.textAlignment = NSTextAlignmentLeft;
        _finalCreateLab.font = kGeneralFontSize;
        _finalCreateLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
//        _finalCreateLab.text = kTestStr;
        _finalCreateLab.numberOfLines = 0;
    }
    return _finalCreateLab;
}

@end
